package juc.utils.phaser;

import java.util.Random;
import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.IntStream;

public class PhaserExample8 {
    private final static Random random = new Random(System.currentTimeMillis());

    /**
     * awaitAdvanceInterruptibly()
     */
    public static void main(String[] args) throws InterruptedException {

        final Phaser phaser = new Phaser(3);
        //Thread thread = new Thread(phaser::arriveAndAwaitAdvance);
        Thread thread = new Thread(() -> {
            try {
                //phaser.awaitAdvanceInterruptibly(phaser.getPhase());
                //6秒超时
                phaser.awaitAdvanceInterruptibly(0, 6, TimeUnit.SECONDS);
            } catch (InterruptedException | TimeoutException e) {
                e.printStackTrace();
            }
        });
        thread.start();
        System.out.println("===");
        TimeUnit.SECONDS.sleep(3);
        thread.interrupt();
        System.out.println("=interrupt==");

    }
}
